<?php
//require section
require_once dirname(__FILE__) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_date.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_contact.php';

$title = 'Hỏi Đáp';

$contact = api_contact::get_contact();
$email = "";
if (!empty($contact['email'])) {
    $email = $contact['email'];
}
$phone = "";
if (!empty($contact['phone'])) {
    $phone = $contact['phone'];
}

$email_sent_to = $email;

if (!empty($_POST)) {
    $txt_full_name = $_POST['txt_full_name'];
    $txt_email = $_POST['txt_email'];
    $txt_phone = $_POST['txt_phone'];
    $txt_question = $_POST['txt_question'];

    //echo $txt_full_name. " ".$txt_email." ".$txt_phone." ".$txt_question." ";
    $message = "Họ tên: " . $txt_full_name
        . " || Email: " . $txt_email
        . " || SĐT: " . $txt_phone
        . " || Câu hỏi: " . $txt_question;

    if (mail($email_sent_to, "huanluyenviencanhan.com.vn - Hỏi đáp", $message)) {
        ?>
        <script type="text/javascript">
            alert('Hệ thống đã gửi email yêu cầu của bạn cho quản trị viên.');
        </script>
    <?php
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <?php
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
    ?>
</head>
<body>
<div class="uk-container uk-container-center uk-margin-top">
    <?php
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php';
    ?>

    <!-- Changable content -->
    <section id="main-content" class="ts-body-container uk-panel uk-panel-box ts-padding-large">
        <article class="uk-article">
            <h1 class="uk-article-title ts-color-primary">Liên Hệ Hỏi Đáp</h1>

            <p class="uk-article-meta">Ngày: <?php echo lib_date::get_now(); ?></p>

            <p class="uk-article-lead">Email: <?php echo $email; ?></p>

            <p class="uk-article-lead">SĐT: <?php echo $phone; ?></p>

            <p class="uk-article-lead">Điền thông tin vào mẫu dưới dây để hệ thống gửi email câu hỏi của bạn cho chúng
                tôi</p>
            <hr class="uk-article-divider">
            <div>
                <form name="form_data" id="form_data" class="uk-form" method="POST" enctype="multipart/form-data"
                      action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">

                    <!-- Hidden Value Section -->

                    <!-- End Hidden Value Section -->

                    <table class="ts-table">
                        <tr>
                            <th><label for="txt_full_name">Tên đầy đủ:<span class="ts-alert">*</span></label></th>
                            <td><input name="txt_full_name" class="uk-form-width-large" type="text"
                                       placeholder="Họ & Tên" required></td>
                        </tr>
                        <tr>
                            <th><label for="txt_email">Email:<span class="ts-alert">*</span></label></th>
                            <td><input name="txt_email" class="uk-form-width-large" type="text" placeholder="Email"
                                       required></td>
                        </tr>
                        <tr>
                            <th><label for="txt_phone">Số điện thoại:<span class="ts-alert">*</span></label></th>
                            <td><input name="txt_phone" class="uk-form-width-large" type="text"
                                       placeholder="Số điện thoại" required></td>
                        </tr>
                        <tr>
                            <th><label for="txt_question">Nội dung thắc mắc:<span class="ts-alert">*</span></label></th>
                            <td><textarea name="txt_question" class="uk-form-width-large" cols="21" rows="5"
                                          required></textarea></td>
                        </tr>
                        <tr>
                            <th></th>
                            <td><input type="submit" name="btn_submit" value="Gửi Yêu Cầu"
                                       class="uk-button uk-button-large uk-button-primary"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </article>
    </section>
    <!-- End changable content -->

    <?php
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
    ?>
</div>
</body>
</html>